
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer

from apps.oauth.constants import OPENID_TOKEN_EXPIRES_TIME
from meiduo_mall import settings
import logging
logger=logging.getLogger('django')
from itsdangerous import SignatureExpired,BadData


def generic_openid_token(openid):

    from meiduo_mall import settings
    s = Serializer(settings.SECRET_KEY, expires_in=OPENID_TOKEN_EXPIRES_TIME)

    data = {
        'openid':openid

    }

    token = s.dumps(data)

    return token.decode()

def check_openid_token(token):
    s=Serializer(secret_key=settings.SECRET_KEY,expires_in=OPENID_TOKEN_EXPIRES_TIME)

    try:
        result=s.loads(token)
    except BadData as e:
        logger.error(e)
        return None
    return result.get('openid')







